Behaviors are sequences of actions that are executed in the proper order and correct setting to achieve a goal. Action sequences and their association with the specific environmental contexts in which they are beneficial can be hardwired, as in the case of innate behaviors, or learned and flexible, as in the case of adaptive responses to changing surroundings. The basal ganglia, a complex set of phylogenetically ancient subcortical nuclei, collect sensorimotor information from across the cortical mantle and project via output nuclei to thalamic structures that regulate action; this circuit organization suggests that the basal ganglia may play key roles in modulating ongoing patterns of action. Consistent with this possibility, neurological and psychiatric diseases that disrupt basal ganglia function also disrupt action selection, sequencing and execution. Furthermore, neural correlates have been identified within the basal ganglia that predict, accompany and lag different features of behavior. However, three key questions remain open about the relationship between basal ganglia activity and behavior. First, it is unclear whether the basal ganglia primarily encode behavioral sequences, the action components of behavioral sequences, or both. Second, because of the temporal diversity of task-related activity observed in the basal ganglia, it is not clear whether activity in specific populations of neurons is causal for behavior. Finally, because most research into basal ganglia function involves overtraining in operant tasks, it is not clear what the core principles of action encoding are that govern basal ganglia function during spontaneously generated patterns of behavior like exploration. Here we propose to take advantage of a novel 3D machine vision technology uses Baysean inference to classify spontaneous behavior on fast (e.g. neural) timescales to probe the causal relationships between neural activity in the basal ganglia and action. We will focus our analysis of the main output nucleus of the basal ganglia; the substantia nigra pars reticulate (SNpr). We will first seek to identify predictive neural correlates within the SNpr for action components and behavioral sequences by combining our behavioral analysis methods with dense electrical recordings, both during normal exploration and during the execution of innate approach and avoidance behaviors triggered by odor cues from foods, conspecifics and predators. We will then test the causal relationship between activity in these SPnr neurons and specific features of behavior by using closed- loop optogenetics to subtly alter global patterns of activity within SPnr neurons themselves. This work will shed light on the mechanisms used by the brain to create self-generated patterns of action, and yield important clues about how the links between neural activity and action are altered during disease.